<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2019/9/22
  Time: 16:00
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>


<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>员工管理</title>
    <%@include file="/WEB-INF/views/common/link.jsp"%>
<script>
    //等页面加载完之后再执行jquery中的函数
    $(function () {
        //去除数组参数中的中括号
        jQuery.ajaxSettings.traditional = true;


        //为元素绑定值改变事件
        $("#checkAll").change(function () {
//            $(".check").prop("checked",$("#checkAll").prop("checked"));
            //事件响应函数中的this指向事件源（为谁绑定的事件，谁就是事件源）
            $(".check").prop("checked",this.checked);
        })

        //批量删除
        $(".btn-batchDelete").click(function () {
            //检查用户是否选择了要删除的数据
            //如果选择的复选框个数为0，说明没有选择
            if($(".check:checked").size() == 0){
                alert("亲，请选择要删除的数据！");
                return;
            }

            //获取选择数据的id

            var ids = [];

            //拿到所有选中的复选框，再获取复选框上绑定的id
            $.each($(".check:checked"),function (index, checkbox) {
                //将DOM对象转换成jQuery对象
                ids.push($(checkbox).data("id"))
            })
            console.log(ids);
            //发送请求（将选中数据的id发送到服务端）

            //参数一：请求资源的路径url
            //参数二：需要提交的参数 ids
            //参数三：当请求响应回来之后执行的函数
            $.get("/employee/batchDelete.do",{ids:ids},function () {
                alert("删除成功");
                window.location.reload();
            })


        })

        //导入
        $(".btn_import").click(function () {
            //将模态框显示出来
            $('#myModal').modal("show");
        })

        //提交表单
        $(".btn-submit").click(function () {
            $("#editForm").submit();
        })
    })
</script>
</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
    <%@include file="/WEB-INF/views/common/navbar.jsp"%>
    <!--菜单回显-->
    <c:set var="currentMenu" value="employee"/>
    <%@include file="/WEB-INF/views/common/menu.jsp"%>
    <div class="content-wrapper">
        <section class="content-header">
            <h1>员工管理</h1>
        </section>
        <section class="content">
            <div class="box">
                <!--高级查询--->
                <form class="form-inline" id="searchForm" action="/employee/list.do" method="post">

                    <div class="form-group">
                        <label for="keyword">关键字:</label>
                        <input type="text" class="form-control" id="keyword" name="keyword" value="${qo.keyword}"  placeholder="请输入姓名/邮箱">
                    </div>
                    <div class="form-group">
                        <label for="dept"> 部门:</label>
                        <select class="form-control" id="dept" name="deptId">
                            <option value="-1">全部</option>

                            <c:forEach items="${depts}" var="dept">
                            <option value="${dept.id}">${dept.name}</option>
                            </c:forEach>

                        </select>
                        <script>
                            $("#dept option[value='${qo.deptId}']").prop("selected", true);
                        </script>
                    </div>
                    <button id="btn_query" class="btn btn-primary"><span class="glyphicon glyphicon-search"></span> 查询</button>

                    <input type="hidden" name="currentPage" id="currentPage" value="1">
                    <a href="/employee/input.do" class="btn btn-success btn-input" style="margin: 10px">
                        <span class="glyphicon glyphicon-plus"></span> 添加
                    </a>
                    <a  class="btn btn-danger btn-batchDelete" style="margin: 10px">
                        <span class="glyphicon glyphicon-remove"></span> 批量删除
                    </a>

                    <a href="/employee/exportXls.do" target="_blank" class="btn btn-warning">
                        <span class="glyphicon glyphicon-export"></span> 导出
                    </a>
                    <a href="javascript:;" class="btn btn-warning btn_import">
                        <span class="glyphicon glyphicon-import"></span> 导入
                    </a>
                </form>
                <!--编写内容-->
                <div class="box-body table-responsive no-padding ">
                    <table class="table table-hover table-bordered">
                        <tr>
                            <th>

                                <input type="checkbox" id="checkAll" />
                            </th>
                            <th>编号</th>
                            <th>员工名称</th>
                            <th>员工邮箱</th>
                            <th>员工年龄</th>
                            <th>员工部门</th>
                            <th>操作</th>
                        </tr>
                        <c:forEach items="${result.list}" var="entity" varStatus="vs">
                            <tr>
                                <%--将数据绑定在复选框上--%>
                                <td><input type="checkbox" class="check" data-id="${entity.id}"/></td>
                                <td>${vs.count}</td>
                                <td>${entity.name}</td>
                                <td>${entity.email}</td>
                                <td>${entity.age}</td>
                                <td>${entity.dept.name}</td>
                                <td>
                                    <a class="btn btn-info btn-xs btn-input" href="/employee/input.do?id=${entity.id}">
                                        <span class="glyphicon glyphicon-pencil"></span> 编辑
                                    </a>
                                    <a href="/employee/delete.do?id=${entity.id}" class="btn btn-danger btn-xs btn-delete">
                                        <span class="glyphicon glyphicon-trash"></span> 删除
                                    </a>
                                </td>
                            </tr>
                        </c:forEach>
                    </table>
                    <!--分页-->
                    <%@include file="/WEB-INF/views/common/page.jsp"%>
                </div>
            </div>
        </section>
    </div>
    <%@include file="/WEB-INF/views/common/footer.jsp"%>
</div>

<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel">员工导入</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/employee/importXls.do" method="post" id="editForm" enctype="multipart/form-data">
                    <div class="form-group">
                        <div class="col-sm-6">
                            <input type="file" name="file" accept="application/vnd.ms-excel"><br/>
                            <a href="/template/employee_import.xls" class="btn btn-success">
                                <span class="glyphicon glyphicon-download-alt"></span> 下载模板
                            </a>
                        </div>

                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary btn-submit">保存</button>
            </div>
        </div>
    </div>
</div>
</body>
</html>
